/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package service.impl;

import dao.AccountDao;
import dao.PetDao;
import dao.PetOwnerDao;
import dao.PetStoreDao;
import dao.impl.AccountMYSQLImpl;
import dao.impl.PetMYSQLImpl;
import dao.impl.PetOwnerMYSQLImpl;
import dao.impl.PetStoreMYSQLImpl;
import entity.Pet;
import entity.PetOwner;
import entity.PetStore;
import java.util.List;
import service.PetOwnerService;

/**
 *
 * @author Administrator
 */
public class PetOwnerServiceImpl implements PetOwnerService {

    @Override
    public PetOwner login(String name, String password) {
        PetOwnerDao pod = new PetOwnerMYSQLImpl();
        PetOwner po = null;
        po = pod.slectOwner(name, password);
        return po;
    }

    @Override
    public void buy(Pet pet, PetOwner po) {

        //宠物主人更新状态
        int state2 = 0;
        PetOwnerDao pod = new PetOwnerMYSQLImpl();
        state2 = pod.Update(pet, po);
        if (state2 == 1) {
            System.out.println("宠物主人信息更新成功！");
        }
        //宠物商店更新状态
        int state3 = 0;
        PetStoreDao psd = new PetStoreMYSQLImpl();
        state3 = psd.update(pet, po);
        if (state3 == 1) {
            System.out.println("宠物商店信息更新成功！");
        }
        //账目表更新状态
        int state4 = 0;
        AccountDao ad = new AccountMYSQLImpl();
        state4 = ad.update(pet, po);
        if (state4 == 1) {
            System.out.println("账目表更新成功！");
        }
        //宠物表更新状态
        int state1 = 0;
        PetDao pd = new PetMYSQLImpl();
        state1 = pd.update(pet, po);
        if (state1 == 1) {
            System.out.println("宠物信息更新成功！");
        }
    }

    @Override
    public List<Pet> getRemainPets() {
        PetDao pd = new PetMYSQLImpl();
        List<Pet> list1 = pd.getRemainPets();
        return list1;
    }

    @Override
    public List<Pet> getPetOwner(int ownerid) {
        PetDao pd = new PetMYSQLImpl();
        List<Pet> list1 = pd.getPetsOwner(ownerid);
        return list1;
    }

    @Override
    public void sellPet(Pet pet, int ownerId, int storeId) {
        //宠物表更新状态
        int state1 = 0;
        PetDao pd = new PetMYSQLImpl();
        state1 = pd.updateSell(pet, storeId);
        if (state1 == 1) {
            System.out.println("宠物信息更新成功！");
        }
        //宠物主人更新状态
        int state2 = 0;
        PetOwnerDao pod = new PetOwnerMYSQLImpl();
        state2 = pod.UpdateSell(pet, ownerId);
        if (state2 == 1) {
            System.out.println("宠物主人信息更新成功！");
        }
        //宠物商店更新状态
        int state3 = 0;
        PetStoreDao psd = new PetStoreMYSQLImpl();
        state3 = psd.updateSell(pet, storeId);
        if (state3 == 1) {
            System.out.println("宠物商店信息更新成功！");
        }
        //账目表更新状态
        int state4 = 0;
        AccountDao ad = new AccountMYSQLImpl();
        state4 = ad.updateSell(pet, ownerId, storeId);
        if (state4 == 1) {
            System.out.println("账目表更新成功！");
        }
    }

    @Override
    public List<PetStore> getAllPetStore() {
        PetStoreDao psd = new PetStoreMYSQLImpl();
        List<PetStore> list1 = psd.getAllStoreInfo();
        return list1;
    }

}
